namespace Peer.Web.Controls.Upload
{
    using System;
    using System.Web;

    internal class UploadStatus : IDisposable
    {
        private DateTime m_beginTime = DateTime.Now;
        private long m_dataLength = 1L;
        private int m_fileCount = 1;
        private string m_fileName = string.Empty;
        private bool m_isActive = true;
        private long m_readLength = 1L;
        private UploadState m_status = UploadState.Initializing;
        private string m_uploadID = Guid.NewGuid().ToString();

        public void Dispose()
        {
        }

        ~UploadStatus()
        {
        }

        public void GetUploadStatus(string m_uploadGUID)
        {
            UploadStatus status = (UploadStatus) HttpContext.Current.Application["Upload_Status_" + m_uploadGUID];
            if (status != null)
            {
                this.m_beginTime = status.m_beginTime;
                this.m_fileCount = status.m_fileCount;
                this.m_fileName = status.m_fileName;
                this.m_dataLength = status.m_dataLength;
                this.m_readLength = status.m_readLength;
                this.m_uploadID = m_uploadGUID;
                this.Status = status.Status;
                this.m_isActive = true;
            }
            else
            {
                this.m_isActive = false;
            }
        }

        public void ResetBeginTime()
        {
            this.m_beginTime = DateTime.Now;
        }

        public long AllDataLength
        {
            get
            {
                return this.m_dataLength;
            }
            set
            {
                if (value < 0L)
                {
                    this.m_dataLength = 1L;
                }
                else
                {
                    this.m_dataLength = value;
                }
            }
        }

        public DateTime BeginTime
        {
            get
            {
                return this.m_beginTime;
            }
            set
            {
                this.m_beginTime = value;
            }
        }

        public int FileCount
        {
            get
            {
                return this.m_fileCount;
            }
            set
            {
                this.m_fileCount = value;
            }
        }

        public string FileName
        {
            get
            {
                return this.m_fileName;
            }
            set
            {
                this.m_fileName = value;
            }
        }

        public bool IsActive
        {
            get
            {
                return this.m_isActive;
            }
        }

        public TimeSpan LeftTime
        {
            get
            {
                if (this.Speed == 0L)
                {
                    return DateTime.Now.Subtract(DateTime.Now.AddSeconds(0.0));
                }
                long num = (this.m_dataLength - this.m_readLength) / this.Speed;
                return DateTime.Now.Subtract(DateTime.Now.AddSeconds((double) -num));
            }
        }

        public long Percent
        {
            get
            {
                if (this.m_dataLength != 0L)
                {
                    return ((100L * this.m_readLength) / this.m_dataLength);
                }
                return 0L;
            }
        }

        public long ReadData
        {
            get
            {
                return this.m_readLength;
            }
            set
            {
                this.m_readLength = value;
            }
        }

        public long Speed
        {
            get
            {
                long totalSeconds = (long) DateTime.Now.Subtract(this.m_beginTime).TotalSeconds;
                if (totalSeconds <= 0L)
                {
                    totalSeconds = 1L;
                }
                return (this.m_readLength / totalSeconds);
            }
        }

        public UploadState Status
        {
            get
            {
                return this.m_status;
            }
            set
            {
                this.m_status = value;
            }
        }

        public string UploadGUID
        {
            get
            {
                return this.m_uploadID;
            }
        }

        public enum UploadState : byte
        {
            Completed = 4,
            Error = 5,
            Initializing = 0,
            Moving = 3,
            Uploaded = 2,
            Uploading = 1
        }
    }
}

